<html>
<head>
	<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
	<meta http-equiv="pragma" content="no-cache" />
	<link rel="stylesheet" href="/css/style.css" type="text/css"/>
	<script type="text/javascript" src="/js/jquery.js"></script>
	<script type="text/javascript" src="/js/util.js"></script>
</head>
<script type="text/javascript">
//////////////////////////////////////////////////////////////////////
////  email = "wenpin.qian@happyelements.com"                     ////
////  team = "Athene"                                             ////
////  warnings = "This is generated page,Do Not Modify!";         ////
////  tips = "Opera & IE not supported|Chrome & Safari sugguested"////
//////////////////////////////////////////////////////////////////////
window.returnValue=0;

$(document).ready(function() {
listselectors();
});

function addshop_item() {
	var addshop_itemUrl = "/shop_item/add/";
	var tabIdValue = $("#tabId").val();
	if(!checkInteger("商城位置页",tabIdValue,false)) {
		return;
	}
	var tabIdParam = "tabId=" + xparseInt(tabIdValue);
		
	var itemIdValue = $("#itemId").val();
	
	var itemIdParam = "itemId=" + itemIdValue;
		
	var coinPriceValue = $("#coinPrice").val();
	if(!checkInteger("金币价格",coinPriceValue,false)) {
		return;
	}
	var coinPriceParam = "coinPrice=" + xparseInt(coinPriceValue);
		
	var silverPriceValue = $("#silverPrice").val();
	if(!checkInteger("银币价格",silverPriceValue,false)) {
		return;
	}
	var silverPriceParam = "silverPrice=" + xparseInt(silverPriceValue);
		
	var statusValue = $("#status").val();
	
	var statusParam = "status=" + statusValue;
		
	var isDiscountValue = $("#isDiscount").val();
	
	var isDiscountParam = "isDiscount=" + isDiscountValue;
		
	var coinPirceDiscountValue = $("#coinPirceDiscount").val();
	if(!checkInteger("金币折扣",coinPirceDiscountValue,false)) {
		return;
	}
	var coinPirceDiscountParam = "coinPirceDiscount=" + xparseInt(coinPirceDiscountValue);
		
	var silverPriceDiscountValue = $("#silverPriceDiscount").val();
	if(!checkInteger("银币折扣",silverPriceDiscountValue,false)) {
		return;
	}
	var silverPriceDiscountParam = "silverPriceDiscount=" + xparseInt(silverPriceDiscountValue);
		
	var levelLimitValue = $("#levelLimit").val();
	if(!checkInteger("等级下限",levelLimitValue,false)) {
		return;
	}
	var levelLimitParam = "levelLimit=" + xparseInt(levelLimitValue);
		
	var vipLevelLimitValue = $("#vipLevelLimit").val();
	if(!checkInteger("VIP等级下限",vipLevelLimitValue,false)) {
		return;
	}
	var vipLevelLimitParam = "vipLevelLimit=" + xparseInt(vipLevelLimitValue);
		
	var rankValue = $("#rank").val();
	if(!checkInteger("排名",rankValue,false)) {
		return;
	}
	var rankParam = "rank=" + xparseInt(rankValue);
		
	var shop_itemresValue = $("#shop_itemres").val();
	
	var shop_itemresParam = "shop_itemres=" + shop_itemresValue;
			
	$.ajax({
		   type: "POST",
		   url: addshop_itemUrl,
		   data:   tabIdParam +'&'+ itemIdParam +'&'+ coinPriceParam +'&'+ silverPriceParam +'&'+ statusParam +'&'+ isDiscountParam +'&'+ coinPirceDiscountParam +'&'+ silverPriceDiscountParam +'&'+ levelLimitParam +'&'+ vipLevelLimitParam +'&'+ rankParam +'&'+ shop_itemresParam ,
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
			       window.returnValue=1;
			       beforeWindowClose();
				   window.close();
			   }else {
				  errDialog(data.message);
			   }
		   }
	});
}

function listselectors() {
var getItemSelectorUrl = "/special/Item/getList/";
$.ajax({
		   type: "GET",
		   url: getItemSelectorUrl,
		   data: "",
		   dataType: "json",
		   success: function(data) {
			   if(data.code > 0) {
				   selectitemId(s2json(data.result));
			   }else {
				   errDialog(data.message);
			   }
		   }
	});
}

function selectitemId(options) {
	var optionHTML = "";
	for(var i in options) {
		optionHTML = optionHTML + "<option value='"+ options[i][0] +"'>" + options[i][1] + "</option>\n";
	}
	$("#itemId").html(optionHTML);
}

function openResource(fieldname,dependfield) {
	var param = "";
	if(dependfield!="") {
		param = $("#" + dependfield).val()
		if(param == null || param == "") {
			alert("你先把【" + $("#lbl_" + dependfield).html() + "】填了再上传");
			return;
		}
	}
	resourceDialog("shop_item",$("#" + fieldname).val(),param,function(result) {
		if(result != undefined && result != "") {
			$("#" + fieldname).val(result);
		}
	});
}

function beforeWindowClose() {
	if(window.returnCallback) {
		window.returnCallback(window.returnValue);
	}
	window.onbeforeunload = null;
	return true;
}

</script>
<body onunload="beforeWindowClose()">
	<div class="addarea">
	<form action="/shop_item/add" method="post">
		<table>
			<tbody>				
					<tr>					<td>
						<label for="tabId" id="lbl_tabId">商城位置页</label>
													<input type="text" id="tabId" name="tabId" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="itemId" id="lbl_itemId">道具</label>
													<select id="itemId" name="itemId">
							</select>
											</td>
					</tr>				
					<tr>					<td>
						<label for="coinPrice" id="lbl_coinPrice">金币价格</label>
													<input type="text" id="coinPrice" name="coinPrice" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="silverPrice" id="lbl_silverPrice">银币价格</label>
													<input type="text" id="silverPrice" name="silverPrice" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="status" id="lbl_status">状态</label>
																				<select id="status" name="status">
								
									<option value="0">普通</option>
								
									<option value="1">新品</option>
								
									<option value="2">热卖</option>
								
									<option value="3">上架</option>
															</select>
											</td>
									
										<td>
						<label for="isDiscount" id="lbl_isDiscount">是否打折</label>
																				<select id="isDiscount" name="isDiscount">
								
									<option value="0">否</option>
								
									<option value="1">是</option>
															</select>
											</td>
					</tr>				
					<tr>					<td>
						<label for="coinPirceDiscount" id="lbl_coinPirceDiscount">金币折扣</label>
													<input type="text" id="coinPirceDiscount" name="coinPirceDiscount" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="silverPriceDiscount" id="lbl_silverPriceDiscount">银币折扣</label>
													<input type="text" id="silverPriceDiscount" name="silverPriceDiscount" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="levelLimit" id="lbl_levelLimit">等级下限</label>
													<input type="text" id="levelLimit" name="levelLimit" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="vipLevelLimit" id="lbl_vipLevelLimit">VIP等级下限</label>
													<input type="text" id="vipLevelLimit" name="vipLevelLimit" /><span class="tips">[整数]</span>
											</td>
					</tr>				
					<tr>					<td>
						<label for="rank" id="lbl_rank">排名</label>
													<input type="text" id="rank" name="rank" /><span class="tips">[整数]</span>
											</td>
									
										<td>
						<label for="shop_itemres" id="lbl_shop_itemres">商城道具资源</label>
													<input type="text" id="shop_itemres" name="shop_itemres" disabled/>
							<input type="button" value="..." onclick="openResource('shop_itemres','')"/><span class="tips">[资源]</span>
											</td>
					</tr>							</tbody>
		</table>
		<input type="button" onclick="addshop_item()" value="添加"/>
	</form>
	</div>
</body>